package com.jinlejia.erp.ui.house.prospect;


import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.jinlejia.erp.R;
import com.jinlejia.erp.databinding.FragmentProspectUploadOfficeBinding;
import com.jinlejia.erp.ui.house.prospect.bean.SurveyPictureBean;

/**
 * 上传或修改
 * 写字楼类
 * 的图片
 */
public class ProspectUploadOfficeFragment extends Fragment implements ProspectUploadImageActivity.HousePictureListener {


    public ProspectUploadOfficeFragment() {
        // Required empty public constructor
    }

    private FragmentHelper fragmentHelper;
    private Helper helper;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        helper = Helper.init(this.getContext());
    }

    private FragmentProspectUploadOfficeBinding binding;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_prospect_upload_office, container, false);
        binding = DataBindingUtil.bind(view);
        if (getArguments() != null) {
            Bundle bundle = getArguments();
            String houseSourceCode = bundle.getString(Type.PARAM.HOUSE_SOURCE_CODE);
            String houseSourceType = bundle.getString(Type.PARAM.HOUSE_SOURCE_TYPE);
            fragmentHelper = FragmentHelper.init(this,houseSourceCode,houseSourceType,helper);
            initView();
        }
        SurveyPictureBean bean = fragmentHelper.getSourceInfo();
        initView(bean);
        return view;
    }

    private void initView() {

        //楼体外景 must 1
        fragmentHelper.createAdapterAndSetToGridView(binding.buildingExteriorGridView,
                binding.buildingExteriorHeaderView,
                1,true,false);

        //大堂（需将电梯照上） must 1
        fragmentHelper.createAdapterAndSetToGridView(binding.lobbyGridView,
                binding.lobbyHeaderView,
                1,true,true);

        //室内照片 must 1
        fragmentHelper.createAdapterAndSetToGridView(binding.indoorGridView,
                binding.indoorHeaderView,
                1,true,true);

        //室外风景图 must 1
        fragmentHelper.createAdapterAndSetToGridView(binding.outdoorGridView,
                binding.outdoorHeaderView,
                1,true,false);
    }

    private void initView(SurveyPictureBean bean){
        if (bean==null)return;
        //楼体外景 must 1
        fragmentHelper.updateAdapterSource(binding.buildingExteriorGridView,
                binding.buildingExteriorHeaderView);

        //大堂（需将电梯照上） must 1
        fragmentHelper.updateAdapterSource(binding.lobbyGridView,
                binding.lobbyHeaderView);

        //室内照片 must 1
        fragmentHelper.updateAdapterSource(binding.indoorGridView,
                binding.indoorHeaderView);

        //室外风景图 must 1
        fragmentHelper.updateAdapterSource(binding.outdoorGridView,
                binding.outdoorHeaderView);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        fragmentHelper.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public String checkPicturesResult() {
        return fragmentHelper.checkPicturesResult();
    }

    @Override
    public SurveyPictureBean getPicturesResult() {
        return fragmentHelper.getPicturesResult();
    }

}
